package com.kehongborui.portal.web;

import com.kehongborui.data.domain.Staff;
import com.kehongborui.data.repository.StaffRepository;
import com.kehongborui.portal.model.StaffModel;
import com.kehongborui.portal.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhang peng yang ming
 * @CopyRight (C) http://www.csdn.com
 * @brief
 * @email 122162005@qq.com
 * @date 2018-09-26
 */
@RestController
@RequestMapping("/staff")
public class StaffController {
    @Autowired
    private StaffService staffService;

    @PostMapping
    public StaffModel create(@RequestBody StaffModel model) {
        return staffService.save(model);
    }

    @GetMapping("/dept/{deptId}")
    public List<StaffModel> create(@PathVariable("deptId") Integer deptId) {
        return staffService.findByDeptId(deptId);
    }

    @GetMapping
    public Page<Staff> findAll() {
        StaffModel staffModel = new StaffModel();
        return staffService.findAll(staffModel, 1, 20);
    }
}
